Fix false positives for unused_enumerated with result member access#6544
Fix false positives for unused_enumerated with result member access#6544theamodhshetty wants to merge 3 commits intorealm:mainfrom
Conversation
Generated by 🚫 Danger |
|
Pushed a small follow-up in The original version reset |
|
Does anything else need to be done to merge this PR? |
|
I don’t think so from my side. The follow-up for the CI/toolchain issue is already in, and the checks are green now. If there’s anything else you want adjusted before merge, I’m happy to make it. |
SimplyDanny
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
The idea looks good. I have a few remarks though ...
Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnusedEnumeratedRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnusedEnumeratedRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnusedEnumeratedRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnusedEnumeratedRule.swift
Outdated
Show resolved
Hide resolved
Source/SwiftLintBuiltInRules/Rules/Idiomatic/UnusedEnumeratedRule.swift
Outdated
Show resolved
Hide resolved
|
Pushed a follow-up in Changes in this pass:
Validation rerun:
If you want this split up differently, I can adjust it. |
| private var currentTrackedClosure: Closure? { | ||
| closures.peek().flatMap(\.self) | ||
| } | ||
|
|
||
| private func popTrackedClosure() -> Closure? { | ||
| closures.pop().flatMap(\.self) | ||
| } | ||
|
|
||
| private func modifyTrackedClosure(_ modifier: (inout Closure) -> Void) { | ||
| closures.modifyLast { | ||
| guard var closure = $0 else { return } | ||
| modifier(&closure) | ||
| $0 = closure | ||
| } | ||
| } |
There was a problem hiding this comment.
I'd prefer to inline them as each of them is only used once.
|
|
||
| guard parent.is(OptionalChainingExprSyntax.self) | ||
| || parent.is(ForceUnwrapExprSyntax.self) | ||
| || parent.is(MemberAccessExprSyntax.self) |
There was a problem hiding this comment.
Also consider tuple expressions with single elements (i.e. parenthesized expressions).
| && arguments.isEmpty | ||
| } | ||
|
|
||
| var usedEnumeratedResultMembers: (zero: Bool, one: Bool) { |
There was a problem hiding this comment.
You may attach this to ExprSyntax instead. So we wouldn't need the while at all and can rely on recursion with the types listed in 319.
Summary
.enumerated()when a higher-order call uses tuple members like?.offsetafter the closure$0.element/$0.0and seed the closure usage from result-member access on the surrounding callTesting
Closes #5881